/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.knolle.vistas;

import javax.swing.*;
import java.util.List;
import javax.swing.event.ListSelectionEvent;
import org.knolle.campanias.util.ListaLotesTransferHandler;
import javax.swing.event.ListSelectionListener;
import org.marcelo.agro.core.api.InterfaceCampanhas;
import org.marcelo.agro.entidades.Lotes;
import org.openide.util.Lookup;

public final class CampaniasVisualPanel2 extends JPanel implements ListSelectionListener {

    public static final String PROPIEDAD_LOTES_SELECCIONADOS = "lotes_seleccionados";
    /**
     * Creates new form CampaniasVisualPanel2
     */
    public CampaniasVisualPanel2() {
        initComponents();
//        listaLotesSeleccionados.getModel().addListDataListener(this);
        listaLotesSeleccionados.addListSelectionListener(this);
        
    }

    @Override
    public String getName() {
        return Bundle.CTL_ActividadesAction();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        //Creando los datos
        //Buscar en el Lookup datos para el
        InterfaceCampanhas ic = Lookup.getDefault().lookup(InterfaceCampanhas.class);
        List<Lotes> lotesList = ic.getLotes();
        DefaultListModel listModel1 = new DefaultListModel();
        ListaLotesTransferHandler handler = new ListaLotesTransferHandler();
        for(Lotes lotes: lotesList){
            listModel1.addElement(lotes);
        }
        jList1 = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaLotesSeleccionados = new javax.swing.JList();

        //Asignar los datos al modelo y el modelo al list
        jList1.setModel(listModel1);
        //Permitir la seleccion
        jList1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        //Permitir arrojar
        jList1.setDragEnabled(true);
        //Setear el handler para la transferencia de DND
        jList1.setTransferHandler(handler);
        jScrollPane1.setViewportView(jList1);

        listaLotesSeleccionados.setModel(new DefaultListModel());
        listaLotesSeleccionados.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        listaLotesSeleccionados.setDragEnabled(true);
        listaLotesSeleccionados.setDropMode(DropMode.INSERT);
        listaLotesSeleccionados.setTransferHandler(handler);
        jScrollPane2.setViewportView(listaLotesSeleccionados);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList listaLotesSeleccionados;
    // End of variables declaration//GEN-END:variables
    
    // Variables de Marcelo - do not modify
    public JList getLotesSeleccionados(){
       return this.listaLotesSeleccionados;
       
    }   
    // End of variables de Marcelo


  

//    @Override
//    public void intervalAdded(ListDataEvent e) {
//        //ignorar
//        if (e.getSource() == (listaLotesSeleccionados)){
//           firePropertyChange(PROPIEDAD_LOTES_SELECCIONADOS, 0, 1);
//        }
//    }

//    @Override
//    public void intervalRemoved(ListDataEvent e) {
//        //ignorar
//        if (e.getSource() == (listaLotesSeleccionados)){
//           firePropertyChange(PROPIEDAD_LOTES_SELECCIONADOS, 0, 1);
//        }
//    }

//    @Override
//    public void contentsChanged(ListDataEvent e) {
//        
//        if (e.getSource() == listaLotesSeleccionados){
//           firePropertyChange(PROPIEDAD_LOTES_SELECCIONADOS, 0, 1);
//        }
//        
//    }

    @Override
    public void valueChanged(ListSelectionEvent e) {
        firePropertyChange(PROPIEDAD_LOTES_SELECCIONADOS, 0, 1);
    }
    
}
